<?php

class Default_Model_News extends Zend_Db_Table {

    protected $_name = 'news';
    protected $_primary = 'newsid';

    public function newsList($arrParam = null, $option = null){
        $db = Zend_Registry::get('connectDb');
        //$db = Zend_Db::factory($adapter, $config);
        $lang = $arrParam['lang'];
        if ($option['task'] == 2){
        	if(isset($lang) && $lang == 'en'){
	            $select = $db->select()
	                    ->from('news AS n', array('newsid', 'title', 'en_content', 'image', 'datecreated AS date'))
                            ->where('status = ?', '1')
	                    ->order('order ASC')
	                    ->limit(2);
	            $result = $db->fetchAll($select);
        	}else{
        		$select = $db->select()
			        		 ->from('news AS n', array('newsid', 'title', 'vi_content', 'image', 'datecreated AS date'))
                                                 ->where('status = ?', '1')
			        		 ->order('order ASC')
			        		 ->limit(2);
        		$result = $db->fetchAll($select);
        	}
        }else{
        	if(isset($lang) && $lang == 'en'){
	            $select = $db->select()
	                    ->from('news AS n', array('newsid', 'title', 'en_content', 'image', 'datecreated AS date'))
                            ->where('status = ?', '1')
	                    ->order('order ASC')
	                    ->limit(8);
	            $result = $db->fetchAll($select);
        	}else{
        		$select = $db->select()
			        		 ->from('news AS n', array('newsid', 'title', 'vi_content', 'image', 'datecreated AS date'))
                                                 ->where('status = ?', '1')
			        		 ->order('order ASC')
			        		 ->limit(8);
        		$result = $db->fetchAll($select);
        	}
        }

        return $result;
    }

    public function newsDetail($arrParam = null, $option = null) {
        $db = Zend_Registry::get('connectDb');
        //$db = Zend_Db::factory($adapter, $config);
        $lang = $arrParam['lang'];
        if(isset($lang) && $lang == 'en'){
        	$select = $db->select()
			        	 ->from('news AS n', array('newsid', 'title', 'en_content', 'datecreated AS date'))
			        	 ->where('newsid = ' . $arrParam['id']);
        	$result = $db->fetchAll($select);
        }else{
        	$select = $db->select()
			        	 ->from('news AS n', array('newsid', 'title', 'vi_content', 'datecreated AS date'))
			        	 ->where('newsid = ' . $arrParam['id']);
        	$result = $db->fetchAll($select);
        }

        return $result;
    }

}